package com.binfast.seed.amiExt;


import com.binfast.common.constant.enums.DeletedStatus;
import com.binfast.seed.base.BaseModel;
import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.mapper.MapperInvoke;

import java.lang.reflect.Method;
import java.util.Date;
import java.util.List;

public class DeleteBatchAmiExt implements MapperInvoke {

    public DeleteBatchAmiExt() {}

    @Override
    public Object call(SQLManager sqlManager, Class aClass, String s, Method method, Object[] objects) {
        if(objects[0] == null) return null;
        List<BaseModel> attrs = (List<BaseModel>) objects[0];
//        List<BaseModel> list = new ArrayList<>();
        if(attrs == null || attrs.size() == 0)return null;
        attrs.parallelStream().forEach(baseModel -> {
//            Map<String,Object> map = new HashMap<>();
//            BaseModel baseModel = (BaseModel)obj;
//            baseModel.setId(Long.parseLong(id == null?"0":id.toString()));
            baseModel.setModifyAt(new Date());
            baseModel.setDeleted(DeletedStatus.DELETED);
//            map.put("id",id);
//            map.put("modifyAt",new Date());
//            map.put("deleted", DeletedStatus.DELETED);
//            list.add(baseModel);
        });
        return sqlManager.updateBatchTemplateById(aClass,attrs);
//        return null;
    }
}
